package goft

import (
	"github.com/gin-gonic/gin"
	"log"
)

func Error(err error, msg ...string) {
	if err != nil {
		log.Println(err.Error())
		mes := err.Error()
		if len(msg) > 0 {
			mes = msg[0]
		}
		panic(mes)
	}
	return
}

func ErrorHandler() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		defer func() {
			if e := recover(); e != nil {
				ctx.AbortWithStatusJSON(400, gin.H{"error": e})
			}
		}()
		ctx.Next()
	}
}
